<template>
	<view class="screen">
		<view class="screen-content">
			<view class="title u-font-md">平台</view>
			<view class="list">
				<block v-for="item in platformList" :key="item.id">
					<view class="item" :class="{active: currentPlatformId == item.id}" @click="handleSelect(item, 'platform')">{{item.name}}</view>
				</block>
			</view>
		</view>
		<view class="screen-content" v-if="selectionFlag">
			<view class="title u-font-md">商品分类</view>
			<view class="list">
				<block v-for="item in goodsList" :key="item.id">
					<view class="item" :class="{active: currentGoodsId == item.id}" @click="handleSelect(item, 'goods')">{{item.name}}</view>
				</block>
			</view>
		</view>
		<view class="screen-content" v-if="talentFlag">
			<view class="title u-font-md">达人等级</view>
			<view class="list">
				<block v-for="item in goodsList" :key="item.id">
					<view class="item" :class="{active: currentGoodsId == item.id}" @click="handleSelect(item, 'goods')">{{item.name}}</view>
				</block>
			</view>
		</view>
		<view class="screen-content">
			<view class="title u-font-md">粉丝要求</view>
			<view class="list">
				<block v-for="item in fansList" :key="item.id">
					<view class="item" :class="{active: currentFansId == item.id}" @click="handleSelect(item, 'fans')">{{item.name}}</view>
				</block>
			</view>
		</view>
		<view class="screen-content">
			<view class="title u-font-md">领域</view>
			<view class="list">
				<block v-for="item in fieldList" :key="item.id">
					<view class="item" :class="{active: currentFieldId == item.id}" @click="handleSelect(item, 'field')">{{item.name}}</view>
				</block>
			</view>
		</view>
		<!-- 按钮 -->
		<view class="screen-btn">
			<ABtn borderRadius="80" @click="handleConfirm" btnHoverClass="btn-hover-class" />
		</view>
	</view>
</template>

<script>
import ABtn from '@/components/a-btn/index.vue'
export default {
	components: {
		ABtn
	},
	props: {
		selectionFlag: {
			type: Boolean,
			default: false
		},
		talentFlag: {
			type: Boolean,
			default: false
		}
	},
	data() {
		return {
			currentPlatformId: -1,
			currentFansId: -1,
			currentFieldId: -1,
			currentGoodsId: -1,
			platformList: [
				{
					id: 1,
					name: '抖音',
				},
				{
					id: 2,
					name: '快手'
				},
				{
					id: 3,
					name: '小红书'
				}
			],
			fansList: [
				{
					id: 4,
					name: '无要求'
				},
				{
					id: 5,
					name: '500+'
				},
				{
					id: 6,
					name: '1000+'
				},
				{
					id: 7,
					name: '1W+'
				},
				{
					id: 8,
					name: '5W+'
				},
				{
					id: 9,
					name: '10W+'
				},
			],
			fieldList: [
				{
					id: 10,
					name: '美妆'
				},
				{
					id: 11,
					name: '护肤'
				},
				{
					id: 12,
					name: '家居'
				},
				{
					id: 13,
					name: '生鲜'
				},
			],
			goodsList: [
				{
					id: 14,
					name: '美食'
				},
				{
					id: 15,
					name: '儿童'
				},
				{
					id: 16,
					name: '女装'
				},
				{
					id: 17,
					name: '男装'
				},
				{
					id: 18,
					name: '美妆'
				},
				{
					id: 19,
					name: '彩妆'
				},
				{
					id: 20,
					name: '玩具'
				},
				{
					id: 21,
					name: '零食'
				}
			],
			resultList: []
		}
	},
	methods: {
		handleSelect(item, str) {
			switch(str) {
				case 'platform':
					if(item.id == this.currentPlatformId) {
						this.currentPlatformId = -1
						this.resultList.splice(this.resultList.findIndex(option => option.id === item.id), 1)
						return
					}
					this.currentPlatformId = item.id
					this.resultList.push(item)
					break
				case 'fans':
					if(item.id == this.currentFansId) {
						this.currentFansId = -1
						this.resultList.splice(this.resultList.findIndex(option => option.id === item.id), 1)
						return
					}
					this.currentFansId = item.id
					this.resultList.push(item)
					break
				case 'field':
					if(item.id == this.currentFieldId) {
						this.currentFieldId = -1
						this.resultList.splice(this.resultList.findIndex(option => option.id === item.id), 1)
						return
					}
					this.currentFieldId = item.id
					this.resultList.push(item)
					break
				case 'goods':
					if(item.id == this.currentGoodsId) {
						this.currentGoodsId = -1
						this.resultList.splice(this.resultList.findIndex(option => option.id === item.id), 1)
						return
					}
					this.currentGoodsId = item.id
					this.resultList.push(item)
					break
			}
		},
		handleConfirm() {
			this.$emit('click', this.resultList)
		}
	}
}
</script>

<style lang="scss" scoped>
.screen {
	padding: 28rpx;
	&-content {
		padding-bottom: 10rpx;
		.title {
			line-height: 56rpx;
			font-weight: 600;
			color: $u-text-color;
		}
		.list {
			display: flex;
			flex-wrap: wrap;
			.item {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 120rpx;
				height: 48rpx;
				border-radius: 48rpx;
				background-color: $u-btn-light-grey-bg-color;
				color: $u-text-color;
				margin: 18rpx 20rpx 18rpx 0;
				&.active {
					background-color: $u-btn-bg-color;
					color: $u-text-white-color;
				}
			}
		}
	}
	&-btn {
		padding: 20rpx 12rpx;
	}
}
</style>
